package com.hackerrank.challenges.anagram;

import java.util.Scanner;

public class Solution {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int T = in.nextInt();
		in.nextLine();
		for(int t = 0; t < T; t++) {
			String ab = in.nextLine();
			if(ab.length() % 2 == 1)
				System.out.println(-1);
			else {
				String a = ab.substring(0, ab.length() / 2), b = ab.substring(ab.length() / 2);
				int n = 0;
				for(char ac : a.toCharArray()) {
					int ind = b.indexOf(ac);
					if(ind < 0)
						n++;
					else
						b = b.substring(0, ind) + b.substring(ind + 1);
				}
				System.out.println(n);
			}
		}
	}
}
